﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Wicture.EPC.Service.V1.Filters
{
    public class UCStringToyota : UCString
    {
        protected override bool MatchLeafNode(ISet<string> saCodes, string leafNode)
        {

            if (_LeafOr == ' ' || !leafNode.Contains(_LeafOr))
            {
                if (leafNode.EndsWith('#'))
                {
                    string modelVinCode = saCodes.LastOrDefault();
                    bool result = modelVinCode.Substring(0, modelVinCode.Length - 1).Equals(leafNode.Substring(0, leafNode.Length - 1));
                    return result;
                }
                else
                {
                    return saCodes.Contains(leafNode);
                }
            }
            else
            {
                var leafNodeList = leafNode.Split(_LeafOr);
                bool result = leafNodeList.Intersect(saCodes).Any();
                //left里面包含#的情况
                if (!result)
                {
                    string modelVinCode = saCodes.LastOrDefault();
                    if (leafNodeList.FirstOrDefault(e => e.Substring(0, e.Length - 1) == modelVinCode.Substring(0, modelVinCode.Length - 1)) != null)
                    {
                        result = true;
                    }
                }
                return result;
            }
        }
    }
}
